//
//  UIColor+HXXColor.m
//  HuiXianxia
//
//  Created by Lrc on 15/5/18.
//  Copyright (c) 2015年 何霄云. All rights reserved.
//

#import "UIColor+HXXColor.h"

@implementation UIColor (HXXColor)

+(UIColor *) colorWithHex:(long)hex alpha:(float)alpha
{
    float red = ((float)((hex & 0xFF0000) >> 16))/255.0;
    float green = ((float)((hex & 0xFF00) >> 8))/255.0;
    float blue = ((float)(hex & 0xFF))/255.0;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

+(UIColor *) colorWithHex:(long)hex
{
    return [self colorWithHex:hex alpha:1];
}

+ (UIColor *)randromColor
{
    float red = ((float)((arc4random()/255 & 0xFF0000) >> 16))/255.0;
    float green = ((float)((arc4random()/255 & 0xFF00) >> 8))/255.0;
    float blue = ((float)(arc4random()/255 & 0xFF))/255.0;
    return [UIColor colorWithRed:red green:green blue:blue alpha:1];
}

+ (UIColor *)colorWithRGBAString:(NSString *)RGBAString {
    
    NSString *pure = [[RGBAString stringByReplacingOccurrencesOfString:@"RGBA(" withString:@""] stringByReplacingOccurrencesOfString:@")" withString:@""];
    
    NSArray *colors = [pure componentsSeparatedByString:@","];
    float red = [colors[0] floatValue]/255.0;
    float green = [colors[1] floatValue]/255.0;
    float blue = [colors[2] floatValue]/255.0;
    float alpha = [colors[3] floatValue];
    
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
@end
